<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 100px;
            height: 100px;
            background: blue;
            position:absolute;
           
        }
        .box2{
            width: 200px;
            height: 200px;
            background: red;
            position: absolute;
            left: 600px;
        }
    </style>
</head>
<body>
    <div class="box1"><strong>壮壮木有小鸡鸡</strong></div>
    <div class="box2"><strong>壮壮没有音杰大</strong></div>
    <script>
        var box1Ele = document.querySelector(".box1");
        var box2Ele = document.querySelector(".box2");
        box1Ele.onmousedown = function(e){
            var x = e.clientX - this.offsetLeft;
            var y = e.clientY - this.offsetTop;
            this.onmousemove = function(e){
                var xx = e.clientX;
                var yy = e.clientY;
                this.style.left = xx - x + "px";
                this.style.top = yy - y + "px";

                // 在移动的时候检测碰撞
                // 找各种大边 小边；
                var AminX = this.offsetLeft;
                var AmaxX = this.offsetLeft + this.offsetWidth;
                

                var BminX = box2Ele.offsetLeft;
                var BmaxX = box2Ele.offsetLeft + box2Ele.offsetWidth;

                if(AmaxX>=BminX && AminX<=BmaxX){
                    console.log("横轴上碰撞了");
                }


            }
        }
        document.onmouseup = function(){
            box1Ele.onmousemove = "";
        }



    </script>
</body>
</html>